(bug 7997) Added ability to Special:Blockip to block users from using Special:Emailuser.
authorDaniel Cannon <amidaniel@users.mediawiki.org>
Thu, 7 Jun 2007 17:31:08 +0000 (17:31 +0000)
committerDaniel Cannon <amidaniel@users.mediawiki.org>
Thu, 7 Jun 2007 17:31:08 +0000 (17:31 +0000)
RELEASE-NOTES
includes/Block.php
includes/DefaultSettings.php
includes/SpecialBlockip.php
includes/SpecialEmailuser.php
includes/SpecialIpblocklist.php
includes/User.php
languages/messages/MessagesEn.php
maintenance/archives/patch-ipb_emailban.sql [new file with mode: 0644]
maintenance/tables.sql
maintenance/updaters.inc

index e6a21ab..ab6672c 100644 (file)
@@ -64,6 +64,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Show result of Special:Booksources in wiki content language always, it's
   normally better maintained than the generic list from the standard message
   files
+* (bug 7997) Added ability of sysops to block users from sending e-mail via
+  Special:Emailuser. This can be disabled by setting $wgSysopEmailBans to
+  false.
 
 == Bugfixes since 1.10 ==
 
index fa98692..c2fc151 100644 (file)
@@ -15,7 +15,8 @@
 class Block
 {
        /* public*/ var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry,
-                               $mRangeStart, $mRangeEnd, $mAnonOnly, $mEnableAutoblock, $mHideName;
+                               $mRangeStart, $mRangeEnd, $mAnonOnly, $mEnableAutoblock, $mHideName, 
+                               $mBlockEmail;
        /* private */ var $mNetworkBits, $mIntegerAddr, $mForUpdate, $mFromMaster, $mByName;
        
        const EB_KEEP_EXPIRED = 1;
@@ -24,7 +25,7 @@ class Block
 
        function __construct( $address = '', $user = 0, $by = 0, $reason = '',
                $timestamp = '' , $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0, 
-               $hideName = 0 )
+               $hideName = 0, $blockEmail = 0 )
        {
                $this->mId = 0;
                # Expand valid IPv6 addresses
@@ -40,7 +41,7 @@ class Block
                $this->mExpiry = self::decodeExpiry( $expiry );
                $this->mEnableAutoblock = $enableAutoblock;
                $this->mHideName = $hideName;
-
+               $this->mBlockEmail = $blockEmail;
                $this->mForUpdate = false;
                $this->mFromMaster = false;
                $this->mByName = false;
@@ -76,7 +77,7 @@ class Block
                $this->mAddress = $this->mReason = $this->mTimestamp = '';
                $this->mId = $this->mAnonOnly = $this->mCreateAccount = 
                        $this->mEnableAutoblock = $this->mAuto = $this->mUser = 
-                       $this->mBy = $this->mHideName = 0;
+                       $this->mBy = $this->mHideName = $this->mBlockEmail = 0;
                $this->mByName = false;
        }
 
@@ -262,6 +263,7 @@ class Block
                $this->mAnonOnly = $row->ipb_anon_only;
                $this->mCreateAccount = $row->ipb_create_account;
                $this->mEnableAutoblock = $row->ipb_enable_autoblock;
+               $this->mBlockEmail = $row->ipb_block_email;
                $this->mHideName = $row->ipb_deleted;
                $this->mId = $row->ipb_id;
                $this->mExpiry = self::decodeExpiry( $row->ipb_expiry );
@@ -371,6 +373,7 @@ class Block
                # Unset ipb_enable_autoblock for IP blocks, makes no sense
                if ( !$this->mUser ) {
                        $this->mEnableAutoblock = 0;
+                       $this->mBlockEmail = 0; //Same goes for email...
                }
 
                # Don't collide with expired blocks
@@ -392,7 +395,8 @@ class Block
                                'ipb_expiry' => self::encodeExpiry( $this->mExpiry, $dbw ),
                                'ipb_range_start' => $this->mRangeStart,
                                'ipb_range_end' => $this->mRangeEnd,
-                               'ipb_deleted'   => $this->mHideName
+                               'ipb_deleted'   => $this->mHideName,
+                               'ipb_block_email' => $this->mBlockEmail
                        ), 'Block::insert', array( 'IGNORE' )
                );
                $affected = $dbw->affectedRows();
index 542b6b2..9830af4 100644 (file)
@@ -971,9 +971,10 @@ $wgHitcounterUpdateFreq = 1;
 
 # Basic user rights and block settings
 $wgSysopUserBans        = true; # Allow sysops to ban logged-in users
-$wgSysopRangeBans              = true; # Allow sysops to ban IP ranges
-$wgAutoblockExpiry             = 86400; # Number of seconds before autoblock entries expire
+$wgSysopRangeBans       = true; # Allow sysops to ban IP ranges
+$wgAutoblockExpiry      = 86400; # Number of seconds before autoblock entries expire
 $wgBlockAllowsUTEdit    = false; # Blocks allow users to edit their own user talk page
+$wgSysopEmailBans       = true; # Allow sysops to ban users from accessing Emailuser
 
 # Pages anonymous user may see as an array, e.g.:
 # array ( "Main Page", "Special:Userlogin", "Wikipedia:Help");
index b434c0a..1211f3f 100644 (file)
@@ -43,6 +43,7 @@ function wfSpecialBlockip( $par ) {
  */
 class IPBlockForm {
        var $BlockAddress, $BlockExpiry, $BlockReason;
+#      var $BlockEmail;
 
        function IPBlockForm( $par ) {
                global $wgRequest, $wgUser;
@@ -60,6 +61,7 @@ class IPBlockForm {
                $this->BlockAnonOnly = $wgRequest->getBool( 'wpAnonOnly', $byDefault );
                $this->BlockCreateAccount = $wgRequest->getBool( 'wpCreateAccount', $byDefault );
                $this->BlockEnableAutoblock = $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
+               $this->BlockEmail = $wgRequest->getBool( 'wpEmailBan', false );
                # Re-check user's rights to hide names, very serious, defaults to 0
                $this->BlockHideName = ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ? 1 : 0;
        }
@@ -238,12 +240,27 @@ class IPBlockForm {
                        </tr>
                        ");
                }
+
+               global $wgSysopEmailBans;
+
+               if ( $wgSysopEmailBans ) {
+                       $wgOut->addHTML("
+                       <tr>
+                       <td>&nbsp;</td>
+                               <td>
+                                       " . wfCheckLabel( wfMsgHtml( 'ipbemailban' ),
+                                                       'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
+                                                               array( 'tabindex' => '10' )) . "
+                               </td>
+                       </tr>
+                       ");
+               }
                $wgOut->addHTML("
                <tr>
                        <td style='padding-top: 1em'>&nbsp;</td>
                        <td style='padding-top: 1em'>
                                " . Xml::submitButton( wfMsg( 'ipbsubmit' ),
-                                                       array( 'name' => 'wpBlock', 'tabindex' => '10' ) ) . "
+                                                       array( 'name' => 'wpBlock', 'tabindex' => '11' ) ) . "
                        </td>
                </tr>
        </table>" .
@@ -356,10 +373,10 @@ class IPBlockForm {
 
                # Create block
                # Note: for a user block, ipb_address is only for display purposes
-
                $block = new Block( $this->BlockAddress, $userId, $wgUser->getID(),
                        $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly,
-                       $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName);
+                       $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName,
+                       $this->BlockEmail);
 
                if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) {
 
@@ -420,6 +437,8 @@ class IPBlockForm {
                        $flags[] = 'nocreate';
                if( !$this->BlockEnableAutoblock )
                        $flags[] = 'noautoblock';
+               if ( $this->BlockEmail )
+                       $flags[] = 'noemail';
                return implode( ',', $flags );
        }
 
index 900a2c3..ca14bd6 100644 (file)
@@ -45,6 +45,13 @@ function wfSpecialEmailuser( $par ) {
                return;
        }
 
+       if ( $wgUser->isBlockedFromEmailUser() ) {
+               // User has been blocked from sending e-mail. Show the std blocked form.
+               wfDebug( "User is blocked from sending e-mail.\n" );
+               $wgOut->blockedPage();
+               return;
+       }
+
        $f = new EmailUserForm( $nu );
 
        if ( "success" == $action ) {
index c947cb5..3530642 100644 (file)
@@ -265,7 +265,7 @@ class IPUnblockForm {
                if( is_null( $msg ) ) {
                        $msg = array();
                        $keys = array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink', 
-                               'anononlyblock', 'createaccountblock', 'noautoblockblock' );
+                               'anononlyblock', 'createaccountblock', 'noautoblockblock', 'emailblock' );
                        foreach( $keys as $key ) {
                                $msg[$key] = wfMsgHtml( $key );
                        }
@@ -306,6 +306,10 @@ class IPUnblockForm {
                        $properties[] = $msg['noautoblockblock'];
                }
 
+               if ( $block->mBlockEmail && $block->mUser ) {
+                       $properties[] = $msg['emailblock'];
+               }
+
                $properties = implode( ', ', $properties );
 
                $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
index f60c429..9b62e2d 100644 (file)
@@ -2149,6 +2149,17 @@ class User {
                return $this->mBlock && $this->mBlock->mCreateAccount;
        }
 
+       /**
+        * Determine if the user is blocked from using Special:Emailuser.
+        *
+        * @public
+        * @return boolean
+        */
+       function isBlockedFromEmailuser() {
+               $this->getBlockedStatus();
+               return $this->mBlock && $this->mBlock->mBlockEmail;
+       }
+
        function isAllowedToCreateAccount() {
                return $this->isAllowed( 'createaccount' ) && !$this->isBlockedFromCreateAccount();
        }
index 0b4f7a8..ab56af0 100644 (file)
@@ -939,7 +939,8 @@ Intended blockee: $7
 
 You can contact $1 or another [[{{MediaWiki:grouppage-sysop}}|administrator]] to discuss the block.
 You cannot use the 'email this user' feature unless a valid email address is specified in your
-[[Special:Preferences|account preferences]]. Your current IP address is $3, and the block ID is #$5. Please include either or both of these in any queries.",
+[[Special:Preferences|account preferences]] and you have not been blocked from using it. 
+Your current IP address is $3, and the block ID is #$5. Please include either or both of these in any queries.",
 'autoblockedtext'           => 'Your IP address has been automatically blocked because it was used by another user, who was blocked by $1.
 The reason given is this:
 
@@ -950,7 +951,8 @@ Expiry of block: $6
 You may contact $1 or one of the other
 [[{{MediaWiki:grouppage-sysop}}|administrators]] to discuss the block.
 
-Note that you may not use the "e-mail this user" feature unless you have a valid e-mail address registered in your [[Special:Preferences|user preferences]].
+Note that you may not use the "e-mail this user" feature unless you have a valid e-mail address 
+registered in your [[Special:Preferences|user preferences]] and you have not been blocked from using it.
 
 Your block ID is $5. Please include this ID in any queries you make.',
 'blockedoriginalsource'     => "The source of '''$1''' is shown below:",
@@ -1967,6 +1969,7 @@ pages that were vandalized).',
 ** Unacceptable username',
 'ipbanononly'                 => 'Block anonymous users only',
 'ipbcreateaccount'            => 'Prevent account creation',
+'ipbemailban'                 => 'Prevent user from sending e-mail',
 'ipbenableautoblock'          => 'Automatically block the last IP address used by this user, and any subsequent IPs they try to edit from',
 'ipbsubmit'                   => 'Block this user',
 'ipbother'                    => 'Other time:',
@@ -1998,6 +2001,7 @@ to a previously blocked IP address or username.',
 'anononlyblock'               => 'anon. only',
 'noautoblockblock'            => 'autoblock disabled',
 'createaccountblock'          => 'account creation blocked',
+'emailblock'                  => 'e-mail blocked',
 'ipblocklist-empty'           => 'The blocklist is empty.',
 'ipblocklist-no-results'      => 'The requested IP address or username is not blocked.',
 'blocklink'                   => 'block',
@@ -2013,6 +2017,7 @@ the list of currently operational bans and blocks.',
 'block-log-flags-anononly'    => 'anonymous users only',
 'block-log-flags-nocreate'    => 'account creation disabled',
 'block-log-flags-noautoblock' => 'autoblock disabled',
+'block-log-flags-noemail'     => 'e-mail blocked',
 'range_block_disabled'        => 'The sysop ability to create range blocks is disabled.',
 'ipb_expiry_invalid'          => 'Expiry time invalid.',
 'ipb_already_blocked'         => '"$1" is already blocked',
diff --git a/maintenance/archives/patch-ipb_emailban.sql b/maintenance/archives/patch-ipb_emailban.sql
new file mode 100644 (file)
index 0000000..b990e42
--- /dev/null
@@ -0,0 +1,4 @@
+-- Add row for email blocks --
+
+ALTER TABLE /*$wgDBprefix*/ipblocks
+       ADD ipb_block_email tinyint(1) NOT NULL default '0';
index 5818543..0fc53aa 100644 (file)
@@ -622,6 +622,9 @@ CREATE TABLE /*$wgDBprefix*/ipblocks (
 
   -- Flag for entries hidden from users and Sysops
   ipb_deleted bool NOT NULL default 0,
+
+  -- Block prevents user from accessing Special:Emailuser
+  ipb_block_email bool NOT NULL default 0,
   
   PRIMARY KEY ipb_id (ipb_id),
 
index e46ec69..c2a69c9 100644 (file)
@@ -76,6 +76,7 @@ $wgNewFields = array(
        array( 'archive',           'ar_len',           'patch-ar_len.sql' ),
        array( 'revision',          'rev_parent_id',    'patch-rev_parent_id.sql' ),
        array( 'page_restrictions', 'pr_id',            'patch-page_restrictions_sortkey.sql' ),
+       array( 'ipblocks',          'ipb_block_email',  'patch-ipb_emailban.sql' ),
 );
 
 function rename_table( $from, $to, $patch ) {